﻿<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="NewUser.aspx.cs" Inherits="NewUser" Title="npljobs.com || New User" %>

<%@ Register Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" TagPrefix="ajax" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="Server">
    <script type="text/javascript">
        var userType = '<%= Request.QueryString["userType"] %>';
        document.body.onload = function () {
            if (userType === 'jobseeker') {
                $('#job-seeker-selection')[0].click();
            }
            else {
                $('#employeer-selection')[0].click();
            }
        }

        function InIEvent() {
        }

        function CheckEmployeerValidation() {
            var required = false;

            var userNameCtrl = $("#<%=txtEmployeerUserName.ClientID %>");
            if ($(userNameCtrl).val().length < 1) {
                $(userNameCtrl).parent().next().css("display", "block");
                $(userNameCtrl).parent().next().html("*");
                required = true;
            }
            else if (!validateEmail($(userNameCtrl).val())) {
                $(userNameCtrl).parent().next().css("display", "block");
                $(userNameCtrl).parent().next().html("*");
                required = true;
            }
            else {
                $(userNameCtrl).parent().next().css("display", "none");
            }

            var passwordCtrl = $("#<%=txtEmployeerPassword.ClientID %>");
            $(passwordCtrl).parent().next().css("display", "none");
            $(passwordCtrl).next().css("display", "none");
            $(passwordCtrl).next().removeClass("short weak good strong");

            if ($(passwordCtrl).val().length < 1) {
                $(passwordCtrl).parent().next().css("display", "block");
                $(passwordCtrl).parent().next().addClass("RequiredMessage");
                $(passwordCtrl).parent().next().html("*");
                required = true;
            }
            else if ($(passwordCtrl).val().length < 6) {
                $(passwordCtrl).next().removeClass("short weak good strong");
                $(passwordCtrl).next().css("display", "block");
                $(passwordCtrl).next().addClass("RequiredMessage error-msg");
                $(passwordCtrl).next().html("The length of password needs to be greater or equal to 6.");
                required = true;
            }
            else {
                if (IsMatchPassword($(passwordCtrl).val(), $("#<%=txtEmployeerConfirmPassword.ClientID %>").val())) {
                    $(passwordCtrl).parent().next().css("display", "none");
                }
                else {
                    $(passwordCtrl).next().html("Password not match");
                    $(passwordCtrl).next().css("display", "block");
                    $(passwordCtrl).next().addClass("RequiredMessage error-msg");
                    required = true;
                }
            }

        var companyCtrl = $("#<%=txtEmployeerCompanyName.ClientID %>");
            if ($(companyCtrl).val().length < 1) {
                $(companyCtrl).parent().next().css("display", "block");
                required = true;
            }
            else
                $(companyCtrl).parent().next().css("display", "none");

            var firstNameCtrl = $("#<%=txtEmployeerFirstName.ClientID %>");
            if ($(firstNameCtrl).val().length < 1) {
                $(firstNameCtrl).parent().next().css("display", "block");
                required = true;
            }
            else
                $(firstNameCtrl).parent().next().css("display", "none");

            var lastNameCtrl = $("#<%=txtEmployeerLastName.ClientID %>");
            if ($(lastNameCtrl).val().length < 1) {
                $(lastNameCtrl).parent().next().css("display", "block");
                required = true;
            }
            else
                $(lastNameCtrl).parent().next().css("display", "none");

            var lastNameCtrl = $("#<%=txtEmployeerPhone.ClientID %>");
            if ($(lastNameCtrl).val().length < 1) {
                $(lastNameCtrl).parent().next().css("display", "block");
                required = true;
            }
            else
                $(lastNameCtrl).parent().next().css("display", "none");

            return required;
        }

        function CheckJobSeekerValidation() {
            var required = false;

            var firstNameCtrl = $("#<%=txtJobSeekerFirstName.ClientID %>");
            if ($(firstNameCtrl).val().length < 1) {
                $(firstNameCtrl).parent().next().css("display", "block");
                required = true;
            }
            else
                $(firstNameCtrl).parent().next().css("display", "none");

            var lastNameCtrl = $("#<%=txtJobSeekerLastName.ClientID %>");
            if ($(lastNameCtrl).val().length < 1) {
                $(lastNameCtrl).parent().next().css("display", "block");
                required = true;
            }
            else
                $(lastNameCtrl).parent().next().css("display", "none");

            var userNameCtrl = $("#<%=txtJobSeekerUserName.ClientID %>");
            if ($(userNameCtrl).val().length < 1) {
                $(userNameCtrl).parent().next().css("display", "block");
                $(userNameCtrl).parent().next().html("*");
                required = true;
            }
            else if (!validateEmail($(userNameCtrl).val())) {
                $(userNameCtrl).parent().next().css("display", "block");
                $(userNameCtrl).parent().next().html("*");
                required = true;
            }
            else {
                $(userNameCtrl).parent().next().css("display", "none");
            }

            var passwordCtrl = $("#<%=txtJobSeekerPassword.ClientID %>");
            $(passwordCtrl).parent().next().css("display", "none");
            $(passwordCtrl).next().css("display", "none");
            $(passwordCtrl).next().removeClass("short weak good strong");

            if ($(passwordCtrl).val().length < 1) {
                $(passwordCtrl).parent().next().css("display", "block");
                $(passwordCtrl).parent().next().addClass("RequiredMessage");
                $(passwordCtrl).parent().next().html("*");
                required = true;
            }
            else if ($(passwordCtrl).val().length < 6) {
                $(passwordCtrl).next().removeClass("short weak good strong");
                $(passwordCtrl).next().css("display", "block");
                $(passwordCtrl).next().addClass("RequiredMessage error-msg");
                $(passwordCtrl).next().html("The length of password needs to be greater or equal to 6.");
                required = true;
            }
            else {
                if (IsMatchPassword($(passwordCtrl).val(), $("#<%=txtJobSeekerConfirmPassword.ClientID %>").val())) {
                    $(passwordCtrl).parent().next().css("display", "none");
                }
                else {
                    $(passwordCtrl).next().html("Password not match");
                    $(passwordCtrl).next().css("display", "block");
                    $(passwordCtrl).next().addClass("RequiredMessage error-msg");
                    required = true;
                }
            }
            return required;
        }

        $(document).ready(function () {
            $("#<%=txtEmployeerPhone.ClientID %>").ForceNumberOnly();
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(InIEvent);

            $(document).ajaxStart(function () {
                $('.waitingChangePassword').show();
            }).ajaxComplete(function () {
                $('.waitingChangePassword').hide();
            });

            $('#<%=txtJobSeekerPassword.ClientID %>').keyup(function () {
                if ($('#<%=txtJobSeekerPassword.ClientID %>').val().length > 0) {
                    var strengthMsg = checkStrength($(this));
                    $(this).next().css("display", "block");
                    $(this).parent().next().css("display", "none");
                    $(this).next().html(strengthMsg);
                }
                else if ($('#<%=txtJobSeekerPassword.ClientID %>').val().length == 0) {
                    $(this).next().css("display", "none");
                }
            })

            $('#<%=txtEmployeerPassword.ClientID %>').keyup(function () {
                if ($('#<%=txtEmployeerPassword.ClientID %>').val().length > 0) {
                    var strengthMsg = checkStrength($(this));
                    $(this).next().css("display", "block");
                    $(this).parent().next().css("display", "none");
                    $(this).next().html(strengthMsg);
                }
                else if ($('#<%=txtEmployeerPassword.ClientID %>').val().length == 0) {
                    $(this).next().css("display", "none");
                }
            })

            function ShowErrorMsg(err, divMsgContainer) {
                var html = '<ul><li>' + err + '</li></ul>';
                $(divMsgContainer).html('');
                $(divMsgContainer).append(html);
                $(divMsgContainer).show("fast", function Hide() {
                    $(divMsgContainer).hide(5000);
                });
            }
            $("#<%=btnEmployeerSave.ClientID %>").click(function (e) {
                var valid = CheckEmployeerValidation();
                if (valid == false) {
                    var parms =
                        {
                            "txtEmployeerUserName": $('#<%=txtEmployeerUserName.ClientID %>').val(),
                            "txtEmployeerPassword": $('#<%=txtEmployeerPassword.ClientID %>').val(),
                            "txtEmployeerCompanyName": $('#<%=txtEmployeerCompanyName.ClientID %>').val(),
                            "ddlCompanyType": $('#<%=ddlCompanyType.ClientID %>').val(),
                            "txtEmployeerFirstName": $('#<%=txtEmployeerFirstName.ClientID %>').val(),
                            "txtEmployeerLastName": $('#<%=txtEmployeerLastName.ClientID %>').val(),
                            "txtEmployeerPhone": $('#<%=txtEmployeerPhone.ClientID %>').val()
                        };
                    var obj = { parms: parms };
                    $.ajax({
                        type: "POST",
                        url: "NewUser.aspx/SaveEmployeer",
                        data: JSON.stringify(obj),
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        async: true,
                        success: function (msg) {
                            var status = msg.d;
                            $("#divEmployeerError").hide();
                            if (status == 'USER_LOGGEDIN') {
                                $("#divEmployeerError").html("Please, Log out to create user");
                                $("#divEmployeerError").show("slow");
                            }
                            else if (status == '') {
                                window.location = "Confirmation.aspx";
                            }
                            else {
                                ShowErrorMsg(status, "#divEmployeerError");
                            }
                        },
                        error: function (data, status, jqXHR) {
                            ShowErrorMsg(status, "#divEmployeerError");
                        }
                    });
                }
                return false;
            });

            $("#<%=btnJobSeekerSave.ClientID %>").click(function (e) {
                var valid = CheckJobSeekerValidation();
                if (valid == false) {
                    var parms =
                        {
                            "txtJobSeekerFirstName": $('#<%=txtJobSeekerFirstName.ClientID %>').val(),
                            "txtJobSeekerLastName": $('#<%=txtJobSeekerLastName.ClientID %>').val(),
                            "txtJobSeekerUserName": $('#<%=txtJobSeekerUserName.ClientID %>').val(),
                            "txtJobSeekerPassword": $('#<%=txtJobSeekerPassword.ClientID %>').val()
                        };

                    var obj = { parms: parms };
                    $.ajax({
                        type: "POST",
                        url: "NewUser.aspx/SaveJobSeeker",
                        data: JSON.stringify(obj),
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        async: true,
                        success: function (msg) {
                            var status = msg.d;
                            $("#divJobSeekerError").hide();
                            if (status == 'USER_LOGGEDIN') {
                                $("#divJobSeekerError").show("slow");
                                $("#divJobSeekerError").html("Please, Log out to create user");
                            }
                            else if (status == '') {
                                window.location = "Confirmation.aspx";
                            }
                            else {
                                ShowErrorMsg(status, "#divJobSeekerError");
                            }
                        },
                        error: function (data, status, jqXHR) {
                            ShowErrorMsg(status, "#divJobSeekerError");
                        }
                    });
                }
                return false;
            });

        });
    </script>

    <asp:UpdatePanel runat="server" ID="upWholePage">
        <ContentTemplate>
            <div class="waitingChangePassword" style="display: none;">
                <img src="images/please_wait.gif" alt="Please wait..." />
            </div>
            <div class="row top-margin">
                <div class="panel panel-default">
                    <!-- Panel Header Here-->
                    <div class="panel-heading orange-gradiant">
                        <h3 class="panel-title text-center">User registration</h3>
                    </div>

                    <div class="tabs tabs-style-topline">
                        <nav>
                            <ul>
                                <li>
                                    <a id="job-seeker-selection" href="#section-topline-1"><span>Job Seeker</span></a>

                                </li>
                                <li>
                                    <a id="employeer-selection" href="#section-topline-2"><span>Employeer</span></a>

                                </li>
                            </ul>
                        </nav>

                        <!-- /content -->
                        <div class="content-wrap">
                            <section id="section-topline-1">
                                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                    <ContentTemplate>
                                        <asp:Panel ID="pnlSearch" runat="server" DefaultButton="btnJobSeekerSave">
                                            <div class="panel-body">
                                                <div class="form-row">
                                                    <div class="GroupHeaderStyle">
                                                        <span>Account Information</span>
                                                    </div>
                                                    <div class="form-body period application-req">
                                                        <div class="row manage-profile row-extra">
                                                            <label class="col-md-4 col-md-4-extra">
                                                                First Name&nbsp;<small>*</small></label>
                                                            <div class="col-md-9">
                                                                <asp:TextBox ID="txtJobSeekerFirstName" CssClass="TextBoxStyle form-control" runat="server" placeholder="Enter First Name"> </asp:TextBox>
                                                            </div>
                                                            <span class="RequiredMessage">*</span>
                                                        </div>
                                                        <div class="row manage-profile row-extra">
                                                            <label class="col-md-4 col-md-4-extra">
                                                                Last Name&nbsp;<small>*</small></label>
                                                            <div class="col-md-9">
                                                                <asp:TextBox ID="txtJobSeekerLastName" CssClass="TextBoxStyle form-control" runat="server" placeholder="Enter Last Name"> </asp:TextBox>
                                                            </div>
                                                            <span class="RequiredMessage">*</span>
                                                        </div>
                                                        <div class="row manage-profile row-extra">
                                                            <label class="col-md-4 col-md-4-extra">
                                                                Email&nbsp;<small>*</small></label>
                                                            <div class="col-md-9">
                                                                <asp:TextBox ID="txtJobSeekerUserName" CssClass="TextBoxStyle form-control" runat="server" MaxLength="50" placeholder="Enter Email"></asp:TextBox>
                                                                <span class="RequiredMessage" id="error-msg">*</span>
                                                            </div>
                                                            <span class="RequiredMessage">*</span>
                                                        </div>
                                                        <div class="row manage-profile row-extra">
                                                            <label class="col-md-4 col-md-4-extra">
                                                                Password&nbsp;<small>*</small></label>
                                                            <div class="col-md-9">
                                                                <asp:TextBox ID="txtJobSeekerPassword" CssClass="TextBoxStyle form-control" runat="server" TextMode="Password" placeholder="Enter Password"></asp:TextBox>
                                                                <span class="RequiredMessage">*</span>
                                                            </div>
                                                            <span class="RequiredMessage">*</span>
                                                        </div>
                                                        <div class="row manage-profile row-extra">
                                                            <label class="col-md-4 col-md-4-extra">
                                                                Confirm Password</label>
                                                            <div class="col-md-9">
                                                                <asp:TextBox ID="txtJobSeekerConfirmPassword" CssClass="TextBoxStyle form-control" runat="server" TextMode="Password" placeholder="Enter Confirm Password"></asp:TextBox>
                                                            </div>
                                                            <span class="RequiredMessage">*</span>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div id="divJobSeekerError" class="message-error row-centered field-validation-valid">
                                                </div>
                                                <div class="row">
                                                    <span class="float-shadow">
                                                        <asp:Button runat="server" Text="Continue" ID="btnJobSeekerSave" OnClick="btnJobSeekerSave_OnClick" OnClientClick="return false;"
                                                            CssClass="btn btn-primary orange-gradiant float-shadow" />
                                                    </span>
                                                </div>
                                            </div>
                                        </asp:Panel>
                                    </ContentTemplate>
                                </asp:UpdatePanel>
                            </section>
                            <section id="section-topline-2">
                                <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                                    <ContentTemplate>
                                        <div class="panel-body">
                                            <asp:Panel ID="Panel1" runat="server" DefaultButton="btnEmployeerSave">
                                                <div class="form-row">
                                                    <div class="GroupHeaderStyle">
                                                        <span>Account Information</span>
                                                    </div>
                                                    <div class="form-body period application-req">
                                                        <div class="row manage-profile row-extra">
                                                            <label class="col-md-4 col-md-4-extra">
                                                                Email&nbsp;<small>*</small></label>
                                                            <div class="col-md-9">
                                                                <asp:TextBox ID="txtEmployeerUserName" CssClass="TextBoxStyle form-control"
                                                                    runat="server" MaxLength="50" placeholder="Enter Email"></asp:TextBox>
                                                                <span class="RequiredMessage" id="Span1">*</span>
                                                            </div>
                                                            <span class="RequiredMessage">*</span>
                                                        </div>
                                                        <div class="row manage-profile row-extra">
                                                            <label class="col-md-4 col-md-4-extra">
                                                                Password&nbsp;<small>*</small></label>
                                                            <div class="col-md-9">
                                                                <asp:TextBox ID="txtEmployeerPassword" CssClass="TextBoxStyle form-control" runat="server" TextMode="Password" MaxLength="50" placeholder="Enter Password"> </asp:TextBox>
                                                                <span class="RequiredMessage">*</span>
                                                            </div>
                                                            <span class="RequiredMessage">*</span>
                                                        </div>
                                                        <div class="row manage-profile row-extra">
                                                            <label class="col-md-4 col-md-4-extra">
                                                                Confirm Password&nbsp;<small>*</small></label>
                                                            <div class="col-md-9">
                                                                <asp:TextBox ID="txtEmployeerConfirmPassword" CssClass="TextBoxStyle form-control" runat="server" TextMode="Password" MaxLength="50" placeholder="Enter Confirm Password"></asp:TextBox>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <br />
                                                <div class="form-row">
                                                    <div class="GroupHeaderStyle">
                                                        <span>Company Details</span>
                                                    </div>
                                                    <div class="form-body period application-req">
                                                        <div class="row manage-profile row-extra">
                                                            <label class="col-md-4 col-md-4-extra">
                                                                Company Name&nbsp;<small>*</small></label>
                                                            <div class="col-md-9">
                                                                <asp:TextBox ID="txtEmployeerCompanyName" CssClass="TextBoxStyle form-control" runat="server" MaxLength="50" placeholder="Enter Company Name"> </asp:TextBox>
                                                            </div>
                                                            <span class="RequiredMessage">*</span>
                                                        </div>
                                                        <div class="row manage-profile row-extra">
                                                            <label class="col-md-4 col-md-4-extra">
                                                                Company Type</label>
                                                            <div class="col-md-9">
                                                                <asp:DropDownList ID="ddlCompanyType" CssClass="formddl" runat="server" AppendDataBoundItems="true"
                                                                    DataTextField="Type" DataValueField="ID">
                                                                    <asp:ListItem Value="-1" Text="Select Company Type"></asp:ListItem>
                                                                </asp:DropDownList>
                                                            </div>
                                                        </div>
                                                        <div class="row manage-profile row-extra">
                                                            <label class="col-md-4 col-md-4-extra">
                                                                Contact First Name&nbsp;<small>*</small></label>
                                                            <div class="col-md-9">
                                                                <asp:TextBox ID="txtEmployeerFirstName" CssClass="TextBoxStyle form-control" placeholder="Enter Contact First Name"
                                                                    runat="server" MaxLength="50"> </asp:TextBox>
                                                            </div>
                                                            <span class="RequiredMessage">*</span>
                                                        </div>
                                                        <div class="row manage-profile row-extra">
                                                            <label class="col-md-4 col-md-4-extra">
                                                                Contact Last Name&nbsp;<small>*</small></label>
                                                            <div class="col-md-9">
                                                                <asp:TextBox ID="txtEmployeerLastName" CssClass="TextBoxStyle form-control" placeholder="Enter Contact Last Name"
                                                                    runat="server" MaxLength="50"> </asp:TextBox>
                                                            </div>
                                                            <span class="RequiredMessage">*</span>
                                                        </div>
                                                        <div class="row manage-profile row-extra">
                                                            <label class="col-md-4 col-md-4-extra">
                                                                Contact Phone&nbsp;<small>*</small></label>
                                                            <div class="col-md-9">
                                                                <asp:TextBox ID="txtEmployeerPhone" CssClass="TextBoxStyle form-control" runat="server" MaxLength="20" placeholder="Enter Contact Phone" />
                                                            </div>
                                                            <span class="RequiredMessage">*</span>
                                                        </div>
                                                    </div>
                                                </div>

                                                <div id="divEmployeerError" class="message-error row-centered field-validation-valid">
                                                    Please, Log out to create user
                                                </div>

                                                <div class="row">
                                                    <span class="float-shadow">
                                                        <asp:Button runat="server" Text="Continue" ID="btnEmployeerSave" OnClick="btnJobSeekerSave_OnClick"
                                                            CssClass="btn btn-primary orange-gradiant float-shadow" />
                                                    </span>
                                                </div>
                                            </asp:Panel>
                                        </div>
                                    </ContentTemplate>
                                </asp:UpdatePanel>
                            </section>
                        </div>
                        <!-- /content -->
                    </div>

                </div>
            </div>
            <script src="Scripts/cbpFWTabs.js"></script>
            <script>
                (function () {

                    [].slice.call(document.querySelectorAll('.tabs')).forEach(function (el) {
                        new CBPFWTabs(el);
                    });

                })();
            </script>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
